var t = getApp();

Page({
    data: {
        language: "",
        ratetextshow: [ "极差", "失望", "一般", "满意", "惊喜" ],
        ratetext: {
            text1: "惊喜",
            text2: "惊喜"
        },
        level: 5,
        level2: 5,
        comment: "",
        order_id: "",
        api: "",
        type: "",
        distributor: {},
        order_list: [],
        jsondata: {},
        order_info: {}
    },
    onLoad: function(t) {
        t.order_id && this.setData({
            order_id: order_id
        }), t.api && this.setData({
            api: api
        }), t.name && this.setData({
            type: name
        });
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {
        this._initData(), this._getDistributor();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getStar: function(t) {
        var e = t.detail;
        this.setData({
            level: e,
            "ratetext.text1": this.data.ratetextshow[e - 1]
        });
    },
    getStar_2: function(t) {
        var e = t.detail;
        this.setData({
            level2: e,
            "ratetext.text2": this.data.ratetextshow[e - 1]
        });
    },
    commentChange: function(t) {
        var e = t.detail;
        this.setData({
            comment: e
        });
    },
    _initData: function() {
        this.setData({
            ratetextshow: [ "极差", "失望", "一般", "满意", "惊喜" ],
            ratetext: {
                text1: "惊喜",
                text2: "惊喜"
            },
            level: 5,
            level2: 5,
            comment: "",
            distributor: {},
            order_list: [],
            jsondata: {},
            order_info: {}
        });
    },
    _getDistributor: function() {
        var e = "", i = this, a = "";
        "delivery" === this.data.type ? (e = "plugin.kingtimes.frontend.distributor.distributorOrderDetail", 
        a += t.getNetAddresss(e), a += "&distributor_order_id=" + this.data.order_id) : "distributor" === this.data.type && (e = "plugin.kingtimes.frontend.order.orderDetail.index", 
        a += t.getNetAddresss(e), a += "&order_id=" + this.data.order_id), t._getNetWork({
            url: a,
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    for (var a = 0; a < e.data.order_goods.length; a++) e.data.order_goods[a].gross_price = (Number(e.data.order_goods[a].goods_price) / e.data.order_goods[a].total).toFixed(2);
                    i.setData({
                        order_info: e.data,
                        order_list: e.data.order_goods,
                        distributor: e.data.distributor
                    });
                } else wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    toComment: function() {
        var t = this;
        0 == this.data.comment.length ? wx.showModal({
            title: "提示",
            content: "您还没有输入相关的评论内容",
            success: function(e) {
                e.confirm && t._submitData();
            }
        }) : this._submitData();
    },
    _submitData: function() {
        var e = t.getNetAddresss(this.data.api), i = {};
        "delivery" === this.data.type ? i = {
            distributor_order_id: this.data.order_id,
            distributor_id: this.data.distributor.id,
            provider_id: this.data.order_info.provider_id,
            content: this.data.comment,
            level: this.data.level
        } : "distributor" === this.data.type && (i = {
            distributor_order_id: this.data.order_id,
            distributor_id: this.data.distributor.id,
            content: this.data.comment,
            level: this.data.level,
            efficiency_level: this.data.level2
        });
        var a = JSON.stringify(i);
        t._postNetWork({
            url: e,
            showToastIn: !1,
            data: a,
            success: function(t) {
                var e = t.data;
                1 == e.result ? wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1500,
                    success: function() {
                        setTimeout(function() {
                            wx.navigateBack({
                                delta: 1
                            });
                        }, 1500);
                    }
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    }
});